package com.example.xiaomaotv.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.xiaomaotv.R;
import com.example.xiaomaotv.entity.Message;

import java.util.List;

public class MessageAdapter extends ArrayAdapter<Message> {
    private int resourceId;
    private List<Message> messageData;
    public MessageAdapter(@NonNull Context context, int resource, @NonNull List<Message> objects) {
        super(context, resource, objects);
        resourceId = resource;
        messageData = objects;
    }
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        Message list = getItem(position);
        View listView = LayoutInflater.from(getContext()).inflate(resourceId,null);
        TextView listName = listView.findViewById(R.id.text_message_name);
        TextView listTime = listView.findViewById(R.id.text_message_time);
        TextView listContent = listView.findViewById(R.id.text_message_content);
        ImageView listImage = listView.findViewById(R.id.img_message_title);
        listName.setText(list.getName());
        listTime.setText(list.getTime());
        listContent.setText(list.getContent());
        listImage.setImageResource(list.getImg());
        return listView;
    }
}
